import request from '@/utils/request'
import type { CategoryCommon } from './types/categoryType'


// 获取资源类别
export type ResourceCategoryData = {
    createdBy: string
    createdTime: string
    id: number
    name: string
    operatorId: string
    selected: boolean
    sort: number
    updatedBy: string
    updatedTime: string
}

export function getResourceCategoryList() {
    return request<CategoryCommon<ResourceCategoryData[]>>({
        url: '/boss/resource/category/getAll',
        method: 'get'
    })
}



// 保存或更新资源类别
type CategoryInfo = Pick<ResourceCategoryData, 'name' | 'sort'> & {id?: number | null}


export function udateOrAddResourceCategory(categoryInfo: CategoryInfo) {
    // 根据请求返回值判断类型
    return request<CategoryCommon<boolean>>({
        url: '/boss/resource/category/saveOrderUpdate',
        method: 'post',
        data: categoryInfo
    })
}



// 删除资源类别
export function deleteResourceCategory(id: number) {
    return request<CategoryCommon<boolean>>({
        url: `/boss/resource/category/${id}`,
        method: 'delete',
        data: {id}
    })
}